package com.aoxin.controller.course.webCourse;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.aoxin.model.SlfActivity;
import com.aoxin.service.inter.course.webCourse.ActivityService;
import com.aoxin.util.AjaxRes;
import com.aoxin.util.Const;
import com.aoxin.util.ThreadLocalUtil;
import com.aoxin.util.enumerate.OperateType;
import com.aoxin.util.log.LogInfo;

@RequestMapping("/web/activity")
@ResponseBody
@Controller
public class ActivityController {

	@Autowired
	private ActivityService slfActivityService;

	/**
	 * 添加活动
	 * 
	 * @param slfActivity
	 * @param ajaxRes
	 */
	@RequestMapping("/insertSlfactivity")
	@LogInfo(operateType = OperateType.INSERT, content = "添加活动")
	public AjaxRes insertSlfactivity(SlfActivity slfActivity, AjaxRes ajaxRes) {
		Integer id = ThreadLocalUtil.getEmployee().getEmployeeId();
		String name = ThreadLocalUtil.getEmployee().getName();
		slfActivity.setEmployeeId(id);
		slfActivity.setEmployeeName(name);
		try {
			Integer integer = slfActivityService.insertSlfactivity(slfActivity);
			if (id != 0 && integer != 0) {
				ajaxRes.setSucceed(integer, Const.SAVE_SUCCEED);
			}

		} catch (Exception e) {
			ajaxRes.setSucceed("insertSlfactivity Failure");
			e.printStackTrace();
		}
		return ajaxRes;
	}

	/**
	 * 批量删除活动
	 * 
	 * @param activityId
	 * @param ajaxRes
	 */
	@RequestMapping("/deleteSlfactivity")
	@LogInfo(operateType = OperateType.DELETE, content = "删除活动")
	public AjaxRes deleteSlfactivity(@RequestParam("activityId") List<Integer> activityId, AjaxRes ajaxRes) {
		try {
			Integer integer = this.slfActivityService.deleteSlfactivity(activityId);
			if (integer != 0) {
				ajaxRes.setSucceedMsg(Const.DEL_SUCCEED);
			}

		} catch (Exception e) {
			ajaxRes.setSucceed("deleteSlfactivity Failure");
			e.printStackTrace();
		}
		return ajaxRes;
	}

	/**
	 * 修改活动
	 * 
	 * @param slfActivity
	 * @param ajaxRes
	 */
	@RequestMapping("/updateSlfactivity")
	@LogInfo(operateType = OperateType.UPDATE, content = "修改活动")
	public AjaxRes updateSlfactivity(SlfActivity slfActivity, AjaxRes ajaxRes) {
		try {
			Integer integer = this.slfActivityService.updateSlfactivity(slfActivity);
			if (integer != 0) {
				ajaxRes.setSucceedMsg(Const.UPDATE_SUCCEED);
			}
		} catch (Exception e) {
			ajaxRes.setSucceed("deleteSlfactivity Failure");
			e.printStackTrace();
		}
		return ajaxRes;
	}

	/**
	 * 活动查询条件
	 * 
	 * @param slfActivity
	 * @param ajaxRes
	 * @return
	 */
	@RequestMapping("/getSlfactivity")
	@LogInfo(operateType = OperateType.QUERY, content = "查询活动条件")
	public AjaxRes getSlfactivity(SlfActivity slfActivity, AjaxRes ajaxRes) {
		List<SlfActivity> integer = slfActivityService.getSlfactivity(slfActivity);
		if (integer != null) {
			ajaxRes.setSucceed("getSlfactivity Fail");
		} else {
			ajaxRes.setFailMsg("pageInfo is null");
		}
		ajaxRes.setSucceed(slfActivity);
		return ajaxRes;

	}

	/**
	 * 活动查询全部
	 * 
	 * @param ajaxRes
	 * @return
	 */
	@RequestMapping("/getBySlfactivity")
	@LogInfo(operateType = OperateType.QUERY, content = "查询活动全部")
	public AjaxRes getBySlfactivity(SlfActivity slfActivity, AjaxRes ajaxRes) {
		try {
			List<SlfActivity> slfActivitys = slfActivityService.getBySlfactivity(slfActivity);
			ajaxRes.setSucceed(slfActivitys, Const.DATA_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;

	}

}
